package real.lang.reflect;

import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

public class RealTypeSignature {

	private EnumerationOfRealTypes realType;

	private Set<EnumerationOfRealSubtypes> realSubtypes = Collections
			.synchronizedSet(EnumSet.noneOf(EnumerationOfRealSubtypes.class));

	private String typeSpace;
	
	/**
	 * @return the realType
	 */
	public EnumerationOfRealTypes getRealTypeEnum() {
		return realType;
	}

	/**
	 * @return the realSubtypes
	 */
	public Set<EnumerationOfRealSubtypes> getRealSubtypesEnum() {
		return realSubtypes;
	}	
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		for (EnumerationOfRealSubtypes subtype : this.realSubtypes) {
			sb.append(subtype.name());
		}
		sb.append(this.realType.name());
		return sb.toString();
	}

	public RealTypeSignature(EnumerationOfRealTypes realType,
			Collection<EnumerationOfRealSubtypes> realSubtypes, String typeSpace) {
		this.realType = realType;
		this.realSubtypes.addAll(realSubtypes);
		this.setTypeSpace(typeSpace);
	}

	/**
	 * @param typeSpace the typeSpace to set
	 */
	private void setTypeSpace(String typeSpace) {
		this.typeSpace = typeSpace;
	}

	/**
	 * @return the typeSpace
	 */
	public String getTypeSpace() {
		return typeSpace;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof RealTypeSignature)
			return this.equals((RealTypeSignature)obj);
		return super.equals(obj);
	}
	public boolean equals(RealTypeSignature sign) 
	{
		return (this.typeSpace.equals(sign.getTypeSpace()) &&
				this.realType.equals(sign.getRealTypeEnum()) &&
				this.realSubtypes.containsAll(sign.getRealSubtypesEnum())
				);
	}
	
}
